﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreeDream.Common
{
    /// <summary>
    /// 工具类
    /// </summary>
    public static class FileUploadHelper
    {
        #region 文件操作

        public static FileInfo[] GetFileInfos(string directorypath)
        {
            if (!IsExistDirectory(directorypath))
            {
                throw new DirectoryNotFoundException();
            }
            var root = new DirectoryInfo(directorypath);
            return root.GetFiles();
        }

        private static bool IsExistDirectory(string directorypath)
        {
            return Directory.Exists(directorypath);
        }

        public static string ReadFile(string path)
        {
            string strMsg = string.Empty;
            if (!File.Exists(path))
            {
                strMsg = "不存在相应的目录";
            }
            else
            {
                var sr = new StreamReader(path, Encoding.Default);
                strMsg = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
            }

            return strMsg;
        }

        public static void FileMove(string orignFile, string newFile)
        {
            File.Move(orignFile, newFile);
        }

        public static void CreateDir(string dir)
        {
            if (dir.Length == 0)
            {
                return;
            }
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
        }

        #endregion
    }
}
